package pers.qianyu.month_202012.date_20201206;

/**
 * [同 date_20201123]
 * 518. 零钱兑换 II
 * https://leetcode-cn.com/problems/coin-change-2/
 *
 * @author mizzle rain
 * @date 2020-12-06 15:56
 */
public class ChangeTwo {
    public int change(int amount, int[] coins) {
        int[][] dp = new int[coins.length + 1][amount + 1];
        for (int i = 0; i < dp.length; i++) {
            dp[i][0] = 1;
        }
        for (int i = 1; i < dp.length; i++) {
            for (int j = 1; j < dp[i].length; j++) {
                if (j - coins[i - 1] >= 0) {
                    dp[i][j] = dp[i - 1][j] + dp[i][j - coins[i - 1]];
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        return dp[coins.length][amount];
    }
}
